<script lang="ts" setup>
import { alertTarget } from "@util/showAlert"

const { show, type, message } = toRefs(alertTarget)
const showImg = ref("/success.svg")

watch(type, (newV) => {
  if (newV === "error") showImg.value = "/error.svg"
  else if (newV === "warn") showImg.value = "/warning.svg"
  else if (newV === "success") showImg.value = "/success.svg"
})

</script>

<template>
  <transition>
    <div class="alert-box" v-if="show">
      <img :src="showImg" alt="icon load error">
      <p>{{message}}</p>
    </div>
  </transition>
</template>

<style lang="scss" scoped>
.alert-box {
  position: fixed;
  top: 40px;
  right: 10px;
  border-radius: 20px;
  background-color: var(--alert-bg);
  padding: 15px;
  display: flex;
  min-width: 240px;

  img {
    width: 50px;
    height: 50px;
  }

  p {
    color: var(--alert-color);
    line-height: 50px;
    margin-left: 12px;
    font-size: 14px;
  }
}

.v-enter-active,
.v-leave-active {
  transition: transform 0.5s ease;
}

.v-enter-from,
.v-leave-to {
  transform: translateX(100%);
}

.v-enter-to,
.v-leave-from {
  transform: translateX(0%);
}

// .v-enter-from,
// .v-leave-to {
//     opacity: 0;
// }
</style>
